package com.dwxt.pay.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.pay.service.WXService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/pay")
public class WXPayController {

    @Autowired
    private WXService wxService;

    /**
     * @param price
     * @param notifyUrl 异步通知链接
     * @param orderId
     * @param type      支付方式 1 app 2扫码
     * @return
     */
    @RequestMapping("/wx")
    public BaseResult payWithWX(@RequestBody Map<String,String> params) throws Exception {
        //String ip = request.getRemoteAddr();
        return wxService.pay(params);
    }

    @RequestMapping("/wx/query")
    public BaseResult queryPayResult(String orderId) throws Exception {
        return wxService.queryPayResult(orderId);
    }

    @RequestMapping("/wx/refund")
    public BaseResult refund(String orderId, Double price) throws Exception {
        return wxService.refund(orderId, price);
    }
}
